/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.action.ticket;

import com.mapping.Dispositivo;
import com.mapping.Empleado;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Ricardo
 */
@Namespace(value = "/")
@Action(value = "altaTicketPre", results = {
    @Result(name = "success", location = "/GestionTicket/agregarTicket.jsp")})
public class AltaTicketPre extends ActionSupport {

    List<Empleado> empleados;
    List<Dispositivo> dispositivos;

    @Override
    public String execute() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();

        TypedQuery e = em.createQuery("SELECT e FROM Empleado e", Empleado.class);
        TypedQuery d = em.createQuery("SELECT d FROM Dispositivo d", Dispositivo.class);
        empleados = e.getResultList();
        dispositivos = d.getResultList();

        em.flush();
        tx.commit();
        em.close();
        return SUCCESS;
    }

    public List<Empleado> getEmpleados() {
        return empleados;
    }

    public List<Dispositivo> getDispositivos() {
        return dispositivos;
    }
}
